local funi = fk.CreateSkill {
  name = "funi",
  tags={Skill.Compulsory}
}

local func={
  mute = true,
  can_trigger = function(self, event, target, player, data)
    if event == fk.RoundStart then
      return player:hasSkill(self)
    elseif event == fk.AfterCardsMove then
      if player:hasSkill(self) and player:getMark("@@funi-turn") == 0 then
        for _, move in ipairs(data) do
          if move.toArea == Card.Void then
            for _, info in ipairs(move.moveInfo) do
              if Fk:getCardById(info.cardId, true).trueName == "shade" then
                return true
              end
            end
          end
        end
      end
    elseif event == fk.CardUsing then
      return target == player and player:getMark("@@funi-turn") > 0
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.RoundStart then
      player:broadcastSkillInvoke(self.name)
      room:notifySkillInvoked(player, self.name, "control")
      local n = (#room.alive_players + 1) // 2
      local ids = getShade(room, n)
      room:askForYiji(player, ids, room.alive_players, self.name, #ids, #ids, "#funi-give", ids)
    elseif event == fk.AfterCardsMove then
      room:setPlayerMark(player, "@@funi-turn", 1)
    elseif event == fk.CardUsing then
      player:broadcastSkillInvoke(self.name)
      room:notifySkillInvoked(player, self.name, "offensive")
      data.disresponsive=true
    end
  end,
}

funi:addEffect(fk.CardUsing,func )
funi:addEffect(fk.RoundStart,func )
funi:addEffect(fk.AfterCardsMove,func )

funi:addEffect("atkrange",{
  correct_func = function (self, from, to)
    if from:hasSkill("funi") then
      return -1000
    end
    return 0
  end,
})

funi:addEffect("targetmod",{
  bypass_distances = function(self, player, skill, card, to)
    return player:getMark("@@funi-turn") > 0
  end,
})

return funi